package com.liuda.commons.function;

import com.liuda.workbench.domain.Activity;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.List;

public class ActivityFunction {
    public static Workbook createWorkBook(List<Activity> activityList){
        Workbook wb = new HSSFWorkbook();
        Sheet sheet1 = wb.createSheet("市场活动表");
        Row row0 = sheet1.createRow(0);
        Cell cell0 = row0.createCell(0);
        cell0.setCellValue("ID");
        cell0 = row0.createCell(1);
        cell0.setCellValue("所有者");
        cell0 = row0.createCell(2);
        cell0.setCellValue("名称");
        cell0 = row0.createCell(3);
        cell0.setCellValue("开始日期");
        cell0 = row0.createCell(4);
        cell0.setCellValue("结束日期");
        cell0 = row0.createCell(5);
        cell0.setCellValue("成本");
        cell0 = row0.createCell(6);
        cell0.setCellValue("描述");
        cell0 = row0.createCell(7);
        cell0.setCellValue("创建时间");
        cell0 = row0.createCell(8);
        cell0.setCellValue("创建者");
        cell0 = row0.createCell(9);
        cell0.setCellValue("最近编辑时间");
        cell0 = row0.createCell(10);
        cell0.setCellValue("最近编辑者");
        if (activityList != null) {
            for (int i = 0; i < activityList.size(); i++) {
                Row row = sheet1.createRow(i + 1);
                Cell cell = row.createCell(0);
                cell.setCellValue(activityList.get(i).getId());
                cell = row.createCell(1);
                cell.setCellValue(activityList.get(i).getOwner());
                cell = row.createCell(2);
                cell.setCellValue(activityList.get(i).getName());
                cell = row.createCell(3);
                cell.setCellValue(activityList.get(i).getStartDate());
                cell = row.createCell(4);
                cell.setCellValue(activityList.get(i).getEndDate());
                cell = row.createCell(5);
                cell.setCellValue(activityList.get(i).getCost());
                cell = row.createCell(6);
                cell.setCellValue(activityList.get(i).getDescription());
                cell = row.createCell(7);
                cell.setCellValue(activityList.get(i).getCreateTime());
                cell = row.createCell(8);
                cell.setCellValue(activityList.get(i).getCreateBy());
                cell = row.createCell(9);
                cell.setCellValue(activityList.get(i).getEditTime());
                cell = row.createCell(10);
                cell.setCellValue(activityList.get(i).getEditBy());
            }
        }
        return wb;
    }
    public static String getHSSFCellValue(HSSFCell cell){
        String value;
        if(cell.getCellType()== HSSFCell.CELL_TYPE_NUMERIC){
            value=cell.getNumericCellValue()+"";
        }else if(cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
            value=cell.getStringCellValue()+"";
        }else if(cell.getCellType()== HSSFCell.CELL_TYPE_BOOLEAN){
            value=cell.getBooleanCellValue()+"";
        }else if(cell.getCellType()== HSSFCell.CELL_TYPE_FORMULA){
            value=cell.getCellFormula()+"";
        }else{
            value="";
        }
        return value;
    }
}
